<div id="app-container" class="container" myapp="STORE_WECHAT_INFOS_EDIT">
  <div class="">
    <a href="#" class="btn btn-primary btn active" style="float:right" role="button">添加好友</a>
    <a class="btn btn-info btn active" href="/ruiqu/store_friends" role="button" style="float:right;margin-right:5px;">好友列表</a>
    <!-- <a href="#" class="btn btn-info btn-lg active" style="float:right;margin-right:5px;" role="button">好友通知</a> -->
  </div>
  <%= hidden_field_tag :authenticity_token, form_authenticity_token, id: 'js-ruiqu-store-friend-index' %>

  <div class="app">
     <div class="app-inner clearfix">
      <div class="widget-list-filter">
        <!-- <%= link_to "添加产品类别", new_ruiqu_store_product_category_path, class: 'ui-btn ui-btn-success' %> -->
        <p class="help-block error-message flash-notice" style=""> <%= notice %></p>
      </div>
         <table id="wechat_table" class="ui-table ui-table-list">
          <thead>
              <tr>
                <th>#</th>
                <th>公司</th>
                <th>系统ID</th>
                <th>请求信息</th>
                <th></th>
                <th>操作</th>
                <th></th>
              </tr>
          </thead>
          <% if @requests.present? %>
          <tbody>
              <% @requests.each_with_index do |hash, i| %>
                <tr>
                  <td>
                    <%= i + 1 %>
                  </td>
                  <td> <%= hash["name"] %></td>
                  <td> <%= hash["uid"] %></td>
                  <td> <%= hash["validation"] %></td>
                  <td></td>
                  <% if hash["agreeable"] == true %>
                    <td>已添加</td>
                  <% else %>
                    <td class="js-agree-friend-<%= hash["base_id"]%>"> <%= link_to '同意请求', '#', class: 'js-accept-friend-request', data: {base_id: hash["base_id"], friend_id: hash["friend_id"]} %></td>
                  <% end %>
                  <td></td>
                </tr>
              <% end %>
          </tbody>
          <% end %>
        </table>
      </div>
  </div>

</div>







<!-- <div class="bs-example" data-example-id="striped-table">
    <table class="table table-striped table-hover">
      <thead>
        <tr>
          <th>#</th>
          <th>公司</th>
          <th>系统ID</th>
          <th>请求信息</th>
          <th></th>
          <th>操作</th>
          <th></th>
        </tr>
      </thead>
      <% if @requests.present? %>
      <tbody>
        <% @requests.each_with_index do |hash, i| %>
          <tr>
            <th scope="row"><%= i + 1 %></th>
            <td> <%= hash["name"] %></td>
            <td> <%= hash["uid"] %></td>
            <td> <%= hash["validation"] %></td>
            <% if hash["agreeable"] == true %>
              <td>已添加</td>
            <% else %>
              <td class="js-agree-friend-<%= hash["base_id"]%>"> <%= link_to '同意请求', '#', class: 'js-accept-friend-request', data: {base_id: hash["base_id"], friend_id: hash["friend_id"]} %></td>
            <% end %>
            <td></td>

            </tr>
          <% end %>
      </tbody>
      <% end %>
    </table>
  </div> -->

<script type="text/javascript">
  $("a.js-accept-friend-request").on("click", function(e){
    e.preventDefault();
    var baseId = $(this).data("base-id");
    var friendId = $(this).data("friend-id");
    var csrf = $("input#js-ruiqu-store-friend-index").val();
    $.ajax({
      url: "/api/store_friends/agree",
      method: "put",
      headers: {
        'X-CSRF-Token': csrf
      },
      data: {
              friend_id: baseId,
              base_id: friendId
            },
      success: function(data){
        if(data.status == true){
          $("td.js-agree-friend-"+ baseId).text("已添加")
        }
      }
    })
  })
</script>
